function slideInCategoryText(categoryLink) {
    if (!categoryLink.parent().is('.current-cat')) {
        categoryLink.stop().css({backgroundPosition: '0px -17px', opacity: 0.0})
            .animate({opacity: 0.7, backgroundPosition: '(0px 45px)'}, 300, 'easeOutQuart');
    }
}

function fadeInCategoryText(categoryLink) {
    if (!categoryLink.parent().is('.current-cat')) {
        categoryLink.stop().animate({opacity: 0.7}, 300, 'easeOutQuart');
    }
}

function slideOutCategoryText(categoryLink) {
    if (!categoryLink.parent().is('.current-cat')) {
        categoryLink.stop().animate({opacity: 0.0, backgroundPosition: '(0px 108px)'}, 300, 'easeInQuart');
    }
}

function fadeOutCategoryText(categoryLink) {
    if (!categoryLink.parent().is('.current-cat')) {
        categoryLink.stop().animate({opacity: 0.0}, 300, 'easeInQuart');
    }
}

function showPosts(contentHtml) {
    (function($) {
        closeLeft();
        closeRight(function() {
            $('#left').html($(contentHtml).find('#left').html());
            $('#right').html($(contentHtml).find('#right').html());
            openLeft();
            openRight();
            setupPhotoGallery();
            setupGuestbookForm();
            setupPhotoPopup();
            setupGoogleMap();
        })
    })(jQuery);
}

function setupPhotoPopup() {
    $("a.popup").fancybox();
}

function setupGoogleMap() {
    $("a.googlemap").attr('href', '#map').fancybox({
        frameWidth: 700,
        frameHeight: 400
    });
}

function closeLeft(callback) {
   if ($('#left').is('.open')) {
       $('#left').animate({right: '35px'}, 700, 'easeOutQuart', function() {
           $(this).animate({right: '35px'}, 300, function() {
               $(this).removeClass('open').addClass('closed');
               if (callback) {
                   callback();
               }
           });
       });
   } else if (callback) {
       callback();
   }
}

function openLeft() {
   $('#left.closed').animate({right: '308px'}, 700, 'easeOutQuart', function() {
       $(this).removeClass('closed').addClass('open');
   });
}

function closeRight(callback) {
   if ($('#right').is('.open')) {
       $('#right').animate({marginLeft: '-290px'}, 700, 'easeOutQuart', function() {
           $(this).animate({marginLeft: '-290px'}, 300, function() {
               $(this).removeClass('open').addClass('closed');
               if (callback) {
                   callback();
               }
           });
       });
   } else if (callback) {
       callback();
   }
}

function openRight() {
    $('#right.closed').animate({marginLeft: '-15px'}, 700, 'easeOutQuart', function() {
       $(this).removeClass('closed').addClass('open');
   });
}
